/*
 *   项目名称：train12306
 *   文件名称：com.xiaolon.train12306.member.controller.MemberController
 *
 *   创建人：  ZHOU XIAO LONG
 *   创建日期：2024/11/8
 *
 */
package com.xiaolon.train12306.member.controller;

import com.xiaolon.train12306.common.resp.CommonResp;
import com.xiaolon.train12306.common.resp.MemberLoginResp;
import com.xiaolon.train12306.member.req.MemberLoginReq;
import com.xiaolon.train12306.member.req.MemberRegisterReq;
import com.xiaolon.train12306.member.req.MemberSendCodeReq;
import com.xiaolon.train12306.member.service.MemberService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/*
 * 类描述：MemberController
 * member接口
 */
@RestController
@RequestMapping("/member")
public class MemberController {

    @Autowired
    MemberService memberService;

    @RequestMapping("/count")
    public CommonResp<Integer> count(){
        int count = memberService.count();
        CommonResp<Integer> commonResp = new CommonResp<>();
        commonResp.setContent(count);
        return commonResp;
    }

    @PostMapping("/register")
    public CommonResp<Long> register(@Valid MemberRegisterReq req){
        System.out.println(req.toString());
        long register = memberService.register(req);
        return new CommonResp<>(register);
    }


    @PostMapping("/send-code")
    public CommonResp<Long> sendCode(@Valid @RequestBody MemberSendCodeReq req){
        memberService.sendCode(req);
        return new CommonResp<>();
    }


    @PostMapping("/login")
    public CommonResp<MemberLoginResp> login(@Valid @RequestBody MemberLoginReq req){
        MemberLoginResp resp = memberService.login(req);
        return new CommonResp<>(resp);
    }
}
